package xiaohu.day0.HJ8;

import java.util.Scanner;
import java.util.TreeMap;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            TreeMap<Integer, Integer> treeMap = new TreeMap<>();
            for (int i = 0; i < n; i++) {
                int key=in.nextInt();
                int value = in.nextInt();
                if (treeMap.containsKey(key)) {
                    treeMap.put(key, treeMap.get(key) + value);
                } else {
                    treeMap.put(key, value);
                }
            }
            //输出
            for (Integer key : treeMap.keySet()) {
                System.out.println(key + " " + treeMap.get(key));
            }
        }
    }
}
